/*
 * ImagePanel.java
 *
 * Created on 17 Temmuz 2008 Perşembe, 21:41
 */

package com.pegaa.uploader.ui.filelist.item;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

/**
 *
 * @author  tayfun
 */
public class ImagePanel extends javax.swing.JPanel {
    
    private BufferedImage image = null;
    private boolean isSelected = false;
    public static final Color LIGHT_GRAY = new Color(240, 230, 200);
    
    /** Creates new form ImagePanel */
    public ImagePanel() {
        initComponents();
    }
    
    public void setImage(BufferedImage image)
    {
        this.image = image;
    }
    
    public void setSelection(boolean b)
    {
        this.isSelected = b;
    }
    
    @Override
    public void paint(Graphics g)
    {
         int imgW, imgH;
         int x, y;
         if(image != null){
             imgW = image.getWidth();
             imgH = image.getHeight();
             x = (this.getWidth()-imgW) >> 1;
             y = (this.getHeight()-imgH) >> 1; 
             
            if(this.isSelected){
                g.setColor(LIGHT_GRAY);
            }else{
                g.setColor(Color.WHITE);
            }
             
            g.fillRect(0, 0,this.getWidth(), this.getHeight());
            g.drawImage(image, x, y, imgW, imgH, this);
         }else{
            g.clearRect(0, 0, this.getWidth(), this.getHeight());
         }  
         super.paintChildren(g);
         g.setColor(Color.darkGray);
         g.drawRect(0, 0, this.getWidth()-1, this.getHeight()-1);
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(1)
            //.addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(1)
            //.addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    
}
